<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_getGridCellInfos"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%;background-color: white"></div>
<script type="text/javascript" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090";
    var map, marker,
            baseUrl = host + "/iserver/services/map-world/rest/maps/世界地图_Day",
            url = host + "/iserver/services/data-world/rest/data";
    map = L.map('map', {
        preferCanvas: true,
        crs: L.CRS.EPSG4326,
        center: {lon: 0, lat: 0},
        maxZoom: 18,
        zoom: 2
    });
    L.supermap.tiledMapLayer(baseUrl, {noWrap: true}).addTo(map);

    map.on("click", function (evt) {
        var x = evt.latlng.lng;
        var y = evt.latlng.lat;
        if (x < -180.0 || x > 180.0 || y < -90 || y > 90) {
            return;
        }
        var getGridCellInfosParam = new SuperMap.GetGridCellInfosParameters({
            dataSourceName: "World",
            datasetName: "WorldEarth",
            X: x,
            Y: y
        });
        L.supermap
                .gridCellInfosService(url)
                .getGridCellInfos(getGridCellInfosParam, function (serviceResult) {
                    if (!serviceResult.result) {
                        return;
                    }
                    if (marker) {
                        marker.setLatLng(evt.latlng);
                    } else {
                        marker = L.marker(evt.latlng).addTo(map);
                    }
                    var innerHTML = resources.text_gridQueryResult + "<br>" + "column: " + serviceResult.result.column + "<br>";
                    innerHTML += "row: " + serviceResult.result.row + "<br>";
                    innerHTML += "value: " + serviceResult.result.value + "<br>";
                    marker.bindPopup(innerHTML).openPopup(marker.getLatLng());
                });
    });
</script>
</body>
</html>